//获取字节数
var getByteOfString = function(string) {
    if (typeof string == 'undefined') {
        console.log('请传入正确的参数');
        return string;
    };
    string = string.toString();
    return string.replace(/[^\x00-\xff]/g, '**').length;
};
//按字节截取字符串
var sliceStringAccordingToByte = function(string, byteNum) {
    if (isNaN(Number(byteNum)) || typeof string == 'undefined') {
        return string;
    };
    string = string.toString();
    var maxlength = Number(byteNum);
    var length = string.replace(/[^\x00-\xff]/g, '**').length;
    if (length <= maxlength) {
        return string;
    };
    var num = 0;
    var sliceStr = '';
    for (var i = 0; i < string.length; i++) {
        var addnum = 0;
        if (/[^\x00-\xff]/g.test(string[i])) {
            addnum = 2;
        } else {
            addnum = 1;
        };
        if (num + addnum > maxlength) {
            sliceStr = string.slice(0, i) + '...';
            break;
        } else {
            num += addnum;
        };
    };
    return sliceStr;
};
//秒转成时间
var secondToTime = function(value) {
    if (typeof value != 'number' || isNaN(value)) {
        return value;
    };
    var number = Number(value);
    var minute = Math.floor(number / 60);
    var second = Math.floor(number % 60);
    if (minute.toString().length < 2) {
        minute = '0' + minute;
    };
    if (second.toString().length < 2) {
        second = '0' + second;
    };
    var str = minute + ':' + second;
    return str;
};
//转成万为单位
var unitTransform = function(value,length) {
    if (isNaN(value)) {
        return value;
    };
    var number = Number(value);
    if (number / 10000 > 1) {
        return length?(number / 10000).toFixed(length)+'万':(number / 10000).toFixed(2) +'万';
    } else {
        return value;
    };
};
// 截取url地址search或者hash 转化成JSON
var sliceUrlConvertToJSON = function(string) {
    var json = {};
    var arr = string.split('&');
    for (var i = 0; i < arr.length; i++) {
        var item = arr[i].split('=');
        var key = item[0].toLowerCase();
        var value = item[1] ? item[1] : '';
        json[key] = value;
    };
    return json;
};
// 截取url地址search或者hash 转化成JSON 改进版
var sliceUrlConvertToJSON1 = function(string) {
    var json = {};
    var arr = string.split('&');
    for (var i = 0; i < arr.length; i++) {
        var item = [];
        var splitNum = arr[i].indexOf('=');
        var key = arr[i].slice(0, splitNum).toLowerCase();
        var value = arr[i].slice(splitNum+1);
        // var key = item[0].toLowerCase();
        // var value = item[1] ? item[1] : '';
        json[key] = value;
    };
    return json;
};
// JSON 转 URL search值格式字符串
var JSONConvertToString = function(json){
    var str = '';
    for(var attr in json){
        str = str + attr + '=' + json[attr] + '&';
    };
    str = str.substring(0,str.length-1);
    return str;
};
// 判断app还是h5
var isAppOrWeb = function() {
    var headStr = window.navigator.userAgent.toLowerCase();
    var bool = null;// true web端口 false app端口
    var system = null;// 1 web 2 安卓 3 ios
    if (headStr.indexOf(';ljlx/') != -1) {
        // 安卓
        system = 2;
        bool = false;
    }else if(headStr.indexOf('ljlx:ios') != -1) {
        // ios
        system = 3;
        bool = false;
    }else {
        // web
        system = 1;
        bool = true;
    };
    return {
        system: system,
        bool: bool
    };
};
// 头部获取search
var getPageSearchToJSON = function() {
    var searchStr = window.location.search.slice(1);
    var searchData = sliceUrlConvertToJSON(searchStr);
    return searchData;
};
var getPageSearchToJSON1 = function() {
    var searchStr = window.location.search.slice(1);
    var searchData = sliceUrlConvertToJSON1(searchStr);
    return searchData;
};